﻿using System.Web.Script.Serialization;
using Synology.DS.Interface.Abstract;
using Synology.DS.Interface.Entities.DiskStation;

namespace Synology.DS.Core.DiskStation
{
    public class StationAccessor
    {
        private readonly IConfigurationManager _config;
        private readonly IWebClient _webClient;

        public StationAccessor(IWebClient webClient, IConfigurationManager config)
        {
            _webClient = webClient;
            _config = config;
        }

        public Response SubmitGetRequest(string path, object request)
        {
            string url = string.Format("{0}/{1}", _config.SynologyApiUrl, path);

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string responseString = _webClient.Get(url, request);
            return serializer.Deserialize<Response>(responseString);
        }

        public Response SubmitPostRequest(string path, object request)
        {
            string url = string.Format("{0}/{1}", _config.SynologyApiUrl, path);

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string responseString = _webClient.Post(url, request);
            return serializer.Deserialize<Response>(responseString);
        }
    }
}
